<template>
  <div class="label">
    <div class="label__title">
      <yk-title :level="4" style="margin: 0;">标签</yk-title>
      <yk-space style="flex: none;">
        <yk-popconfirm title="新建标签" @cancel="cancel" @confirm="confirm" placement="bottom">
          <yk-text type="primary">
            <IconCirclePlusOutline style="margin-right: 4px;"></IconCirclePlusOutline>
            新建标签
          </yk-text>
          <template #content>
            <div style="margin: 8px 4px 16px;">
              <yk-input show-counter :limit="6" placeholder="请输入" style="width: 208px;" v-model="inputValue"></yk-input>
            </div>
          </template>
        </yk-popconfirm>
        <yk-text type="primary" @click="showModal">
          <IconSettingsOutline style="margin-right: 4px;"></IconSettingsOutline>
          管理标签
        </yk-text>
      </yk-space>
    </div>
    <yk-space wrap size="s">
      <yk-tag v-for="item in label" :key="item.id">
        {{ item.label_name }}
      </yk-tag>
    </yk-space>
  </div>
  <yk-modal :content-height="300" v-model="visible" @onSubmit="visible = false" title="管理分组">
    <labelManage :label="label" @deleteLabel="deleteLabel"></labelManage>
  </yk-modal>
</template>

<script setup lang="ts">
import { onMounted } from 'vue';
import labelManage from './labelManage.vue';

import { useLabel } from '@/hooks/label';

const {
  inputValue,
  label,
  rawLabel,
  cancel,
  confirm,
  visible,
  showModal,
  deleteLabel
} = useLabel()





onMounted(() => {
  rawLabel();
});
</script>

<style lang="less" scoped>
// 颜色变量
@primary-color: #3a7bd5;
@primary-light: rgba(58, 123, 213, 0.08);
@text-color: #2c3e50;
@text-light: #5e6c84;
@bg-color: #ffffff;
@bg-light: #f9fafc;
@border-color: #edf0f5;
@shadow-color: rgba(0, 0, 0, 0.06);
@transition: all 0.3s cubic-bezier(0.25, 1, 0.5, 1);

.label {
  padding: 22px 24px;
  border-radius: 14px;
  background-color: @bg-color;
  width: 100%;
  box-shadow: 0 4px 20px @shadow-color;
  border: 1px solid @border-color;
  transition: @transition;

  &:hover {
    box-shadow: 0 6px 24px rgba(0, 0, 0, 0.08);
  }

  &__title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 18px;
    position: relative;

    // 装饰性左侧边框
    :deep(.yk-title) {
      position: relative;
      padding-left: 14px;

      &::before {
        content: '';
        position: absolute;
        left: 0;
        top: 2px;
        bottom: 2px;
        width: 4px;
        background: linear-gradient(to bottom, @primary-color, lighten(@primary-color, 15%));
        border-radius: 2px;
      }
    }

    // 操作按钮样式
    .yk-text[type="primary"] {
      display: flex;
      align-items: center;
      padding: 6px 10px;
      border-radius: 6px;
      transition: @transition;
      font-size: 14px;
      color: @primary-color;

      &:hover {
        background-color: @primary-light;
        color: darken(@primary-color, 10%);
      }

      .yk-icon {
        margin-right: 6px;
        transition: transform 0.3s;
      }

      &:hover .yk-icon {
        transform: scale(1.1);
      }
    }
  }

  // 标签列表样式
  :deep(.yk-space) {
    margin-top: 14px;

    .yk-tag {
      background-color: @bg-light;
      border-color: @border-color;
      color: @text-light;
      font-size: 13px;
      padding: 0 12px;
      height: 28px;
      line-height: 26px;
      border-radius: 14px;
      margin-bottom: 10px;
      transition: @transition;

      &:hover {
        color: @primary-color;
        background-color: @primary-light;
        border-color: rgba(58, 123, 213, 0.2);
        transform: translateY(-2px);
      }
    }
  }
}

// 弹窗样式优化
:deep(.yk-popconfirm-content) {
  border-radius: 12px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.12);
  overflow: hidden;

  .yk-popconfirm__title {
    font-weight: 600;
    padding: 14px 16px;
    border-bottom: 1px solid @border-color;
  }

  .yk-input {
    .yk-input__inner {
      border-radius: 8px;
      transition: all 0.3s;

      &:focus {
        border-color: @primary-color;
        box-shadow: 0 0 0 2px rgba(58, 123, 213, 0.2);
      }
    }
  }

  .yk-popconfirm__action {
    justify-content: flex-end;
    padding: 10px 16px;
    border-top: 1px solid @border-color;
    background-color: @bg-light;
  }
}

// 标签管理模态框样式
:deep(.yk-modal) {
  .yk-modal-header {
    border-bottom: 1px solid @border-color;
    padding: 16px 20px;

    .yk-modal-title {
      font-weight: 600;
      font-size: 18px;
    }
  }

  .yk-modal-body {
    padding: 20px;
  }

  .yk-modal-footer {
    border-top: 1px solid @border-color;
    padding: 12px 20px;
    background-color: @bg-light;
  }
}

// 响应式调整
@media (min-width: 1200px) {
  .label {
    padding: 24px 28px;
  }
}

@media (max-width: 992px) {
  .label {
    padding: 20px 22px;

    &__title {
      margin-bottom: 16px;
    }
  }
}

@media (max-width: 768px) {
  .label {
    padding: 18px 20px;
    border-radius: 12px;

    &__title {
      flex-wrap: wrap;
      gap: 12px;
      margin-bottom: 14px;

      :deep(.yk-title) {
        width: 100%;
      }

      .yk-space {
        width: 100%;
        justify-content: space-between;
      }
    }

    :deep(.yk-space) {
      margin-top: 12px;

      .yk-tag {
        font-size: 12px;
        padding: 0 10px;
        height: 26px;
        line-height: 24px;
        margin-bottom: 8px;

        &:hover {
          transform: translateY(-1px);
        }
      }
    }
  }
}

@media (max-width: 576px) {
  .label {
    padding: 16px;
    border-radius: 10px;

    &__title {
      margin-bottom: 12px;

      :deep(.yk-title) {
        font-size: 16px;
        padding-left: 12px;

        &::before {
          width: 3px;
        }
      }

      .yk-text[type="primary"] {
        font-size: 13px;
        padding: 5px 8px;
      }
    }
  }
}

@media (max-width: 480px) {
  .label {
    padding: 14px;

    :deep(.yk-space) {
      gap: 8px;

      .yk-tag {
        margin-bottom: 6px;
      }
    }

    &__title {
      .yk-text[type="primary"] {
        .yk-icon {
          margin-right: 4px;
          font-size: 14px;
        }
      }
    }
  }
}
</style>
